package com.kingint.web.util;

import com.kingint.mbg.bas.entity.BasRoomState;
import com.kingint.mbg.bas.entity.BasServiceClass;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.List;

/**
 * 菜单工具类
 */
public class MenuUtil {

    public static void cancelServiceClass(List<BasServiceClass> aClass, List<BasServiceClass> allList) {
        if (!CollectionUtils.isEmpty(aClass)) {
            //为一级菜单设置子菜单
            for (BasServiceClass info : aClass) {
                getChildList(info, allList);
            }
        }
    }

    public static void getChildList(BasServiceClass info, List<BasServiceClass> aClass) {
        List<BasServiceClass> serviceClass = info.getChildServiceClass();
        if (CollectionUtils.isEmpty(serviceClass)) {
            serviceClass = new ArrayList<>();
        }
        for (BasServiceClass ser : aClass) {
            if (ser.getPid() == info.getId()) {
                serviceClass.add(ser);
            }
        }
        //递归查询
        if (serviceClass.size() != 0) {
            for (BasServiceClass child : serviceClass) {
                getChildList(child, aClass);
            }
        }
        info.setChildServiceClass(serviceClass);
    }

    /**
     * @param aClass
     */
    public static void cancelRoomState(List<BasRoomState> aClass, List<BasRoomState> allList) {
        if (!CollectionUtils.isEmpty(aClass)) {
            //为一级菜单设置子菜单
            for (BasRoomState info : aClass) {
                getRoomChildList(info, allList);
            }
        }
    }

    public static void getRoomChildList(BasRoomState info, List<BasRoomState> aClass) {
        List<BasRoomState> serviceClass = info.getRoomStates();
        if (CollectionUtils.isEmpty(serviceClass)) {
            serviceClass = new ArrayList<>();
        }
        for (BasRoomState ser : aClass) {
            if (ser.getPid() == info.getId()) {
                serviceClass.add(ser);
            }
        }
        //递归查询
        if (serviceClass.size() != 0) {
            for (BasRoomState child : serviceClass) {
                getRoomChildList(child, aClass);
            }
        }
        info.setRoomStates(serviceClass);
    }
}
